package com.zq.im;

import android.util.Log;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;

/**
 * Created by 张强 869518570@qq.com on 2020/8/13
 */
public class Demo {
    public static void main(String[] args) {
        connetToServer();
    }


    private static WebSocketClient webSocketClient;

    private static void connetToServer(){
        try {
            webSocketClient = new WebSocketClient(new URI("ws://192.168.1.50:8080/ws"), new Draft_6455() {},null,100000) {
                @Override
                public void onOpen(ServerHandshake handshakedata) {
                    Log.e("JWebSocketClient", "onOpen()");
                }
                @Override
                public void onMessage(String message) {
                    Log.e("JWebSocketClient", "onMessage()");
                }
                @Override
                public void onClose(int code, String reason, boolean remote) {
                    Log.e("JWebSocketClient", "onClose()");
                }
                @Override
                public void onClosing(int code, String reason, boolean remote) {
                    super.onClosing(code, reason, remote);
                }
                @Override
                public void onError(Exception ex) {
                    Log.e("JWebSocketClient", "onError()");
                }
            };
        } catch (Exception e) {
            e.printStackTrace();
        }
        webSocketClient.connect();
    }
}
